<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/static/admin/jsp/include.jsp"%>
    <link rel="stylesheet" href="${path}/static/admin/goodsEth/upload.css">
    <%--<script src="${path}/static/admin/goodsEth/jquery.min.js"></script>--%>
    <script type="text/javascript">
        var sy = sy || {};
        sy.contextPath = '${path}';
        var idarr = "${idarr}";

        $(function(){
            if (idarr != '') {
                $.post(sy.contextPath + '/goods/findByGoods', {
                    idarr : idarr
                }, function (result) {

                    var html = '';
                    for(var i = 0; i< result.length; i++){
                        html += '<div class="upload_item est">';
                        html += '    <p class="name" data-id="'+result[i].id+'">'+result[i].goodsName+'</p>';
                        html += '    <div class="pic">';
                        var imgarr = new Array();
                        imgarr = result[i].goodsImgs.split(",");
                        for (var j = 0; j < imgarr.length; j++){
                            html += '       <div class="pic_item">';
                            html += '           <input class="pic_check" checked type="checkbox" name="img" value="'+imgarr[j]+'">';
                            html += '           <label class="check_icon"><img src="${path}/static/admin/goodsEth/check_icon.png"></label>';
                            html += '           <img class="item_img" src="${path}/download?id='+imgarr[j]+'">';
                            html += '       </div>';
                        }
                        html += '   </div>';
                        html += '</div>';
                    }
                    $("#fileUp").append(html)
                });
            }
        });
    </script>
</head>
<body>
<div class="upload_wrap">
    <div class="upload_table">
        <div class="upload_head upload_item">
            <span class="name">商品名称</span>
            <span class="pic">图片</span>
        </div>
        <div class="upload_box">
            <form class="upload_form" id="fileUp">
            </form>
        </div>
    </div>
    <%--<div class="shop_btn"><a class="btn_submit" href="javascript:void(0);">确定</a></div>--%>
</div>

<script src="${path}/static/admin/goodsEth/jquery.nicescroll.js"></script>
<script>
    // 提交
    var submitForm = function($dialog, $grid, $pjq) {
        var json_data = [];
        var i = 0;
        $('.upload_item.est').each(function(){
            var json_item = {};
            var goods_id = $(this).find('p.name').attr('data-id');
            json_item.goodsId = goods_id;
//
//            var j = 0;
//            var json_img_item = [];
//            $(this).find('.pic_check:checked').each(function(){
//                var img = $(this).val();
//                json_img_item[j] = img;
//                j++;
//            });
//            json_item.imgarrs = json_img_item;
//
//            json_data[i] = json_item;
            var img = "";
            var imgs = "";
            $(this).find('.pic_check:checked').each(function(){
                var img = $(this).val();
                img = img +",";
                imgs += img;
            });
            json_item.imgs = imgs
            json_data[i] = json_item;
            i++;
        });
        var url = sy.contextPath + '/goodsEthLogs/upEthList';
        var data = {goodsEthLogs : JSON.stringify(json_data)};

        $.post(url, data, function(result) {
            console.log(result);
            if (result.code == 0) {
                $grid.datagrid('reload');
                $dialog.dialog('destroy');
            } else {
                $pjq.messager.e('保存失败,'+result.errorMsg);
            }
        }, 'json');
    };
</script>
</body>
</html>